from django.conf import settings
from itsdangerous import TimedJSONWebSignatureSerializer as Serializer



class SecretOauth(object):
    # 加密
    def dumps(self, content_dict):
        # 1.根据签名(secret_key)创建序列化对象
        serializer = Serializer(secret_key=settings.SECRET_KEY, expires_in=24*15*60)
        # 2.通过dumps方法加密数据
        result = serializer.dumps(content_dict)
        # 3.result是byte类zing转换成str
        return result.decode()

    # 解密
    def loads(self, content_dict):
        # 1.根据签名创建序列化对象
        serializer = Serializer(secret_key=settings.SECRET_KEY, expires_in=24*15*60)
        # 2.通过loads方法解密
        result = serializer.loads(content_dict)
        # 3.返回解密完毕的数据
        return result